All Questions
214 questions
5votes
6answers
2kviews
Bubble sort with 10 random numbers
I want to make a bubble sorting algorithm of 10 random (non-repeating) numbers from 0-50. I changed many aspects of it while making it and finally got it to work, but I would like to see if there's ...
7votes
4answers
1kviews
LeetCode 977: Squares of a sorted array, maintaining non-decreasing order
I tried solving the LeetCode question like many others, trying to incorporate the O(n) time complexity requirement. Squares of a Sorted Array Given an integer array ...
5votes
2answers
199views
Sorting file names of a RAR split archive (v3 and v5)
This simple task of sorting a list of related RAR files of a split archive turned out to be more cumbersome than expected, since there are two versions of the RAR naming scheme, v3 and v5. v3 is like ...
5votes
1answer
123views
Sorting songs with the ability to save and resume partial sorts
I listen to a lot of music (~4k h/y) and managing thousands of songs is a bit of a challenging. To improve my listening experience I want to better organize my collection. One thing I want to do is ...
8votes
3answers
2kviews
Algorithm "sort except zero"
Task: Sort the integers in sequence in sequence. But the position of zeros should not be changed. Input: List of integers (int). Output: List or another Iterable (tuple, generator, iterator) of ...
9votes
3answers
2kviews
Sorting array by odd numbers while leaving the even numbers in the same spots
The problem given was: "You will be given an array of numbers. You have to sort the odd numbers in ascending order while leaving the even numbers at their original positions." I developed a ...
4votes
2answers
165views
Sort a dict by keys, assuming keys are orderable
I found a suspicious code snipped in an existing project in which I am involved as a developer. The code sorts a dict by its keys, so that if iterated over the dict,...
6votes
2answers
314views
A selection sort implemented in Python
I'm not proficient at Python. My question is twofold: whether this selection sort algorithm implementation for number lists could be considered clean code (in the sense of being modular and ...
3votes
1answer
171views
Optimizing my sorting function
I created my own list sorting function with Python: ...
5votes
2answers
2kviews
Sort a Python list of strings where each item is made with letters and numbers
I have a set of strings that all consist of one or two letters followed by one or two digits. I need to sort by the letters then by the numeric value of the digits. My solution is quite inefficient ...
3votes
1answer
130views
Optimize mergesort algorithm
I just started Stanford Coursera algorithms course and I wrote this mergesort based on what was shown: ...
1vote
1answer
105views
Simple sort function
I am learning Python and for practice I have written this function which sorts a list. Can you please provide feedback on how I have structured it and what better ways could be there to write it for ...
5votes
3answers
891views
Counting swaps in a sequence sorting algorithm
I have been working on this question, https://open.kattis.com/problems/sequences. You are given a sequence, in the form of a string with characters ‘0’, ‘1’, and ‘?’ only. Suppose there are n ‘?’s. ...
3votes
1answer
119views
Sorting algorithm in the element cost model Python
1. Task Using standard input I read four rows of data: number of elements (elements are numbered from 1 to n) n numbers corresponding to cost of moving each element n numbers corresponding to current ...
1vote
1answer
174views
Insertion Sort- inserting from the left
I've implemented my own insertion sort algorithm, and here's the code. ...